package com.gowants.pems.service;

import com.gowants.pems.mapper.EquipmentPartMapper;
import com.gowants.pems.mapper.EquipmentPartRecordMapper;
import com.gowants.pems.model.EquipmentPartRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class EquipmentPartRecordService {
    @Autowired
    private EquipmentPartRecordMapper mapper;

    @Autowired
    private EquipmentPartMapper partMapper;

    /**
     * 设备配件操作记录
     * @param record
     * @return
     */
    @Transactional(rollbackFor = {Exception.class})
    public int saveEquipmentPartRecord(EquipmentPartRecord record){
        int i=0;
        i=mapper.insert(record);
        int count=0;
        switch (record.getType()){
            case 1:
            case 3:
                count= record.getCount();
                break;
            case 2:
                count= - record.getCount();
                break;
        }
        partMapper.updateCount(record.getPid(),count);
        return i;
    }
}
